﻿using Common.Models;
using Core.Entities.EQ;
using Infrastructure.Services;
using Infrastructure.Services.EQ;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace WebZHX.Controllers.Equipment
{
    /// <summary>
    /// 设备状态报警信息控制器
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class DevStatusController : BaseController<DevStatus, string>
    {
        private readonly DevStatusService _devStatusService;

        public DevStatusController(
            BaseService<DevStatus, string> service,
            DevStatusService devStatusService)
            : base(service)
        {
            _devStatusService = devStatusService;
        }

        /// <summary>
        /// 根据设备编码查询
        /// </summary>
        /// <param name="devCode">设备编码</param>
        /// <returns>设备状态报警信息列表</returns>
        [HttpGet("code/{devCode}")]
        public async Task<ActionResult<IEnumerable<DevStatus>>> GetByDevCode(string devCode)
        {
            var result = await _devStatusService.GetByDevCodeAsync(devCode);
            return Ok(result);
        }

        /// <summary>
        /// 根据设备名称模糊查询
        /// </summary>
        /// <param name="devName">设备名称</param>
        /// <returns>设备状态报警信息列表</returns>
        [HttpGet("name/{devName}")]
        public async Task<ActionResult<IEnumerable<DevStatus>>> GetByDevName(string devName)
        {
            var result = await _devStatusService.GetByDevNameAsync(devName);
            return Ok(result);
        }

        public class DevStatusQueryDto
        {
            /// <summary>
            /// 分页数据
            /// </summary>
            public QueryFilter filter { get; set; }
            /// <summary>
            /// 实体数据
            /// </summary>
            public DevStatus DevStatus { get; set; }
        }

        /// <summary>
        /// 高级分页查询
        /// </summary>
        /// <param name="devStatusQueryDto">查询参数</param>
        /// <returns>分页结果</returns>
        [HttpPost("DevStatusPage")]
        public async Task<ActionResult<PagedResult<DevStatus>>> AdvancedPagedQuery([FromBody] DevStatusQueryDto devStatusQueryDto)
        {
            var result = await _devStatusService.GetByDevStatusAsync(devStatusQueryDto.filter, devStatusQueryDto.DevStatus);
            return Ok(result);
        }

        // 注意：这里移除了新增、修改、删除的方法，因为前端不需要这些操作
    }
}